import React, { useEffect, useState } from "react";
import {InputNumberProps} from "antd";
import {NumberPicker} from "@formily/antd";
import { setThousandth } from '@/utils/utils';

interface NumberPProps extends InputNumberProps {

}

/**
 * 数值型组件
 * 增加了千分位的格式化
 * @param props
 */
export default (props: NumberPProps) => {
  return props?.editable
    ? <NumberPicker
    formatter={
      value => {
        return `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
      }
    }
    parser={
      (value: string ) => {
        return value.replace(/,/g, '')
      }
    }
    {...props}
  /> : setThousandth(props?.value);
}
